package com.itheima.zuoye.zy1;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Test {
    public static void main(String[] args) {
//        ：对一组学生数据按照年纪进行升序排序，如果年纪一致按照身高进行降序排序
        ArrayList<Students> students = new ArrayList<>();
        students.add(new Students("小王", 18, 170));
        students.add(new Students("小张", 17, 180));
        students.add(new Students("小李", 18, 165));
        students.add(new Students("小王", 17, 170));
        students.add(new Students("小王", 18, 170));
//        按照年纪进行升序排序，如果年纪一致按照身高进行降序排序
        Collections.sort(students, new Comparator<Students>() {
            @Override
            public int compare(Students o1, Students o2) {
                int num = o1.getAge() - o2.getAge();
                if (num == 0) {
                   Double.compare(o1.getHeight(), o2.getHeight()); // 身高降序
                }
                return num;
            }
        });

        // 打印排序后的结果
        for (Students s : students) {
            System.out.println(s);
        }


        }





    }

